class Solution {
    public:
        vector<int> twoSum(vector<int>& nums, int target) {
            int n = nums.size();
            unordered_map<int,int> um;
            for(int i = 0;i < n;i++){
                if(um.count(target - nums[i]))
                {
                    return {um[target - nums[i]],i};
                }else{
                    um[nums[i]] = i;
                }
            }
            return {};
        }
    };

class Solution {
    public:
        vector<vector<string>> groupAnagrams(vector<string>& strs) {
            map<vector<int>,vector<string> > window;
            int n = strs.size();
            for(int i = 0;i < n;i++){
                string& str = strs[i];
                vector<int> arr(26);
                for(char c : str){
                    arr[c - 'a']++;
                }
                window[arr].push_back(str);
            }
            vector<vector<string>> ans;
            for(auto&e : window){
                vector<string> str;
                str.swap(e.second);
                ans.push_back(str);
            }
            return ans;
        }
    };
    class Solution {
        public:
            int longestConsecutive(vector<int>& nums) {
                unordered_set<int> st(nums.begin(),nums.end());
                int ans = 0;
                for (int x : st) {
                    if(st.contains(x - 1)){
                        continue;
                    }
                    int y = x + 1;
                    while(st.contains(y))
                        y++;
                        ans = max(ans,y - x);
                }
                return ans;
            }
        };
        class Solution {
            public:
                void moveZeroes(vector<int>& nums) {
                    int i0 = 0;
                    for (auto& x : nums) {
                        if (x) {
                            swap(x, nums[i0]);
                            i0++;
                        }
                    }
                }
            };
1
class Solution {
    public:
        int maxArea(vector<int>& height) {
            int n = height.size();
            int left = 0,right = n - 1,ans = 0;
            while(left < right){
                if(height[left] < height[right]){
                    ans = max(ans,height[left] * (right - left));
                    left++;
                }else{
                    ans = max(ans,height[right] * (right - left));
                    right--;
                }
            }
            return ans;
        }
    };
1
class Solution {
    public:
        vector<vector<int>> threeSum(vector<int>& nums) {
            sort(nums.begin(),nums.end());
            int n = nums.size();
            vector<vector<int>> ans;
            for(int i = 0;i < n;i++){
                int x = nums[i];
                if(i && nums[i - 1] == x){
                    continue;
                }
                int j = i + 1,k = n - 1;
                while(j < k){
                    int y = nums[j],z = nums[k];
                    if(x + y + z < 0){
                        j++;
                    }else if(x + y + z > 0){
                        k--;
                    }else{
                        ans.push_back({x,y,z});
                        while(j < k && nums[j] == y) j++;
                        while(j < k && nums[k] == z) k--;
                    }
                }
            }
            return ans;
    
        }
    };
1
class Solution {
    public:
        int trap(vector<int>& height) {
            int n = height.size(), left = 0, right = n - 1, ans = 0;
            int leftmax = 0, rightmax = 0;
            while (left < right) {
                leftmax = max(leftmax, height[left]);
                rightmax = max(rightmax, height[right]);
                ans += leftmax < rightmax ? leftmax - height[left++]
                                          : rightmax - height[right--];
            }
            return ans;
        }
    };
1
class Solution {
    public:
        int lengthOfLongestSubstring(string s) {
            int n = s.size();
            vector<int> m(256);
            int left = 0,right = 0;
            int ans = 0;
            for(;right < n;right++){
                m[s[right]]++;
                while(m[s[right]] == 2){
                    m[s[left]]--;
                    left++;
                }
                ans = max(ans,right - left + 1);
            }
            return ans;
        }
    };
1
class Solution {
    public:
        vector<int> findAnagrams(string s, string p) {
            vector<int> ans,tmp(26),mode(26);
            int n = s.size(),m = p.size();
            for(char c : p) mode[c - 'a']++;
            for(int i = 0;i < n;i++){
                tmp[s[i] - 'a']++;
                if(i >= m){
                    tmp[s[i - m] - 'a']--;
                }
                if(tmp == mode){
                    ans.push_back(i - m + 1);
                }
            }
            return ans;
        }
    };